#pragma once
#include "resource.h"       // main symbols
#include <atlctl.h>
#include "AddinLib_i.h"

using namespace ATL;


class CConfigHelper  {

public:

	// Normally the location of the application is hardcoded, but we allow registry
	// key override for debugging/development
	void GetAppUrl(BSTR * pUrl) {
		CComBSTR appUrl = "http://bedatadriven.com";
		wchar_t appUrlBuffer[1024];
		ULONG appUrlLength;
		
		CRegKey addinKey;
		LONG hRetVal;
		
		hRetVal = addinKey.Open(HKEY_CURRENT_USER, 
			_T("SOFTWARE\\Microsoft\\Office\\PowerPoint\\Addins\\GWTExample.OfficeAddin"), KEY_READ);
		if(hRetVal == ERROR_SUCCESS) {
			hRetVal = addinKey.QueryStringValue(_T("AppURL"),appUrlBuffer, &appUrlLength);
		}
		if(hRetVal == ERROR_SUCCESS) {
			// the returned string is null terminated 
			// but BSTRs are length-prefixed, so do not copy the last character
			appUrl = CComBSTR(appUrlLength-1, appUrlBuffer);
		}
		addinKey.Close();
		appUrl.CopyTo(pUrl);
	}

};